package com.xiaotu.test;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.xiaotu.common.util.CacheHandler;
import com.xiaotu.common.util.RegexUtils;
import com.xiaotu.common.util.StringUtil;
import com.xiaotu.server.service.maoyan.MaoYanMovieBasicInfoService;

public class MaoYanShadowBoxSpiderData {
	
	@SuppressWarnings({ "resource", "unchecked" })
	public static void main(String[] args) {
		//注入MaoYanMovieBasicInfoService
		MaoYanMovieBasicInfoService maoYanMovieBasicInfoService = (MaoYanMovieBasicInfoService) new ClassPathXmlApplicationContext("application-context.xml").getBean("maoYanMovieBasicInfoService"); 
		
		CacheHandler cacheHandler = (CacheHandler)new ClassPathXmlApplicationContext("application-context.xml").getBean("cacheHandler");
		
		List<Map<String, Object>> movList = maoYanMovieBasicInfoService.queryBoxOfficeDetailList();
		movList.forEach(movMap ->
        {
        	String dataid = RegexUtils.regexSearch(RegexUtils.REGEX_INTEGER, StringUtil
                    .nullToString(movMap.get("dataid")));
            if (StringUtils.isEmpty(dataid))
                return;
            Map<String, Object> paramMap = new HashMap<String, Object>();
            paramMap.put("dataid", dataid);
            paramMap.put("mvname", StringUtil.nullToString(movMap.get("mvname")));
            paramMap.put("playdate", StringUtil.nullToString(movMap.get("playdate")));
            paramMap.put("playtype", StringUtil.nullToString(movMap.get("playtype")));
            cacheHandler.hSet("MAOYAN_SHADOW_BOX", movMap.get("dataid")+"_"+movMap.get("playdate")+"_"+movMap.get("playtype"), paramMap);
        });
		
	}
}
